import { ref } from 'vue'
import { defineStore } from 'pinia'
import * as fileApi from '@/api/fileApi'
import {useFileListStore} from "@/stores/fileListStore.js";

export const usePreviewInfoStore = defineStore('previewInfoStore', () => {

  const show = ref(false)
  const title = ref('属性')
  const fileInfo = ref({})
  const icon = ref(null)
  async function info() {
    let fileList = Array.from(useFileListStore().selectedFiles).map(item => JSON.parse(item.getAttribute("data-obj")));
    let absolutePathList = fileList.map(item => item.absolutePath)
    if(absolutePathList.length === 0) return
    if (absolutePathList.length === 1) {
      icon.value = absolutePathList[0]
    }else {
      icon.value = null
    }
    let res = await fileApi.info(absolutePathList)
    fileInfo.value = res.data
    show.value = true
  }

  function clear() {
    icon.value = null
    fileInfo.value = {}
  }

  return {show,info,title,fileInfo,icon,clear}

})
